var baseURL = "../";
$(function(){
    getData1();
    $("#binding").click(function () {
        getBinding();
    })
});

function getData1(){
    var uuid = $.query.get("uuid");

    $("#uuid").val(uuid);
}
function getBinding() {
    var openId=$("#uuid").val();
    var phone=$("#phone").val()
    if(phone==null)
        if (phone == '') {
            layer.msg('电话不能为空');
            return false;
        }
    if (!isPoneAvailable(phone)) {
        layer.msg('电话号码不正确');
        return false;
    }
    // layer.msg(openId)
    if(openId!=null&&openId!=undefined&&openId!=""){
        var url = baseURL + "/questionnaire/binding?uuid="+ openId+"&phone="+phone;
        $.ajax({
            url: url,
            type: "get",
            dataType: "text",
            success: function (data) {
                // layer.msg(data)
                if (data == "success") {
                    // layer.confirm('添加成功!是否关闭窗口?', function (index) {
                    layer.msg("绑定成功！");
                    // window.location.reload();
                    var url = getRootPath()+"/modules/editAlumni.html.html?uuid="+$("#uuid").val();//此处拼接内容
                    window.location.href = url;
                    // window.location.href=getRootPath()+'/modules/winSuccess.html';

                    return false;
                    // });
                } else {
                    layer.msg('绑定失败！号码有误或号码已绑定！');
                }
            }
        })
    }
}
//js获取项目根路径，如： http://localhost:8083/uimcardprj
function getRootPath(){
    //获取当前网址，如： http://localhost:8083/uimcardprj/share/meun.jsp
    var curWwwPath=window.document.location.href;
    //获取主机地址之后的目录，如： uimcardprj/share/meun.jsp
    var pathName=window.document.location.pathname;
    var pos=curWwwPath.indexOf(pathName);
    //获取主机地址，如： http://localhost:8083
    var localhostPaht=curWwwPath.substring(0,pos);
    //获取带"/"的项目名，如：/uimcardprj
    var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1);
    return(localhostPaht+projectName);
}

function isPoneAvailable(pone) {
    var myreg=/^[1][3,4,5,7,8][0-9]{9}$/;
    if (!myreg.test(pone)) {
        return false;
    } else {
        return true;
    }
}